package com.xyazm.order.api;

import com.xyazm.common.core.JsonResult;
import com.xyazm.order.domain.param.PayRefundCallbackParam;
import com.xyazm.order.domain.param.ReceiveCustomerAfterSaleParam;
import com.xyazm.order.domain.param.ReceiveCustomerAuditResultParam;
import com.xyazm.order.exception.OrderBizException;
import com.xyazm.order.service.IAfterSaleService;
import com.xyazm.order.service.IApplyAfterSaleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 订单售后对外提供api实现类
 * @Author: xuyou
 * @Date: 2022/7/6 9:44
 */
@Slf4j
@DubboService(version = "1.0.0",interfaceClass = IOrderAfterSaleApi.class)
public class OrderAfterSaleApi implements IOrderAfterSaleApi {

    @Autowired
    private IAfterSaleService afterSaleService;

    @Autowired
    private IApplyAfterSaleService applyAfterSaleService;


    @Override
    public JsonResult<Boolean> refundCallback(PayRefundCallbackParam param) {
        try {
            afterSaleService.payRefundCallback(param);
            return JsonResult.buildSuccess();
        } catch (OrderBizException e) {
            log.error("biz error", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch(Exception e) {
            log.error("system error", e);
            return JsonResult.buildError(e.getMessage());
        }
    }


    @Override
    public JsonResult<Boolean> receiveCustomerAuditResult(ReceiveCustomerAuditResultParam param) {
        try {
            applyAfterSaleService.receiveCustomerAuditResult(param);
            return JsonResult.buildSuccess();
        } catch (OrderBizException e) {
            log.error("biz error", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch(Exception e) {
            log.error("system error", e);
            return JsonResult.buildError(e.getMessage());
        }
    }

    @Override
    public JsonResult<Long> customerFindAfterSaleRefundInfo(ReceiveCustomerAfterSaleParam param) {
        try {
            Long afterSaleRefundId = afterSaleService.customerFindAfterSaleRefundInfo(param);
            return JsonResult.buildSuccess(afterSaleRefundId);
        } catch (OrderBizException e) {
            log.error("biz error", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch(Exception e) {
            log.error("system error", e);
            return JsonResult.buildError(e.getMessage());
        }
    }



}
